package cn.south.campus.admin.campus.model.vo;

import cn.south.campus.admin.campus.model.entity.Ad;
import cn.south.campus.common.file.service.ImgJsonDeSerializer;
import cn.south.campus.common.file.service.ImgJsonSerializer;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/11 10:13
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AdVO extends BaseVO {
    /**
     * 广告位posNo
     */
    private String posNo;

    /**
     * 广告位名称
     */
    private String positionName;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 图片
     */
    @JsonSerialize(using = ImgJsonSerializer.class)
    @JsonDeserialize(using = ImgJsonDeSerializer.class)
    private String pic;
    /**
     * 链接
     */
    private String url;

    /**
     * 开始时间
     */
    private String startTime;

    /**
     * 结束时间
     */
    private String endTime;

    public static AdVO convert(Ad ad) {
        if (ad == null) {
            return null;
        }
        AdVO adVO = new AdVO();
        adVO.setId(ad.getId());
        adVO.setPosNo(ad.getPosNo());
        adVO.setPositionName(ad.getPositionName());
        adVO.setTitle(ad.getTitle());
        adVO.setContent(ad.getContent());
        adVO.setUrl(ad.getUrl());
        adVO.setPic(ad.getPic());
        adVO.setStartTime(DateUtil.format(ad.getStartTime()));
        adVO.setEndTime(DateUtil.format(ad.getEndTime()));
        return adVO;
    }

    public static Ad convert(AdVO adVO) {
        if (adVO == null) {
            return null;
        }
        Ad ad = new Ad();
        ad.setId(adVO.getId());
        ad.setPosNo(adVO.getPosNo());
        ad.setPositionName(adVO.getPositionName());
        ad.setTitle(adVO.getTitle());
        ad.setContent(adVO.getContent());
        ad.setUrl(adVO.getUrl());
        ad.setPic(adVO.getPic());
        ad.setStartTime(DateUtil.parseString(adVO.getStartTime()));
        ad.setEndTime(DateUtil.parseString(adVO.getEndTime()));
        return ad;
    }
}
